#ifndef _HTTPCREDENTIALS_HPP_
#define _HTTPCREDENTIALS_HPP_

#include "jhdefs.hpp"
#include "net/HTTPDigestCredentials.hpp"
#include "net/HTTPRequest.hpp"
#include "net/HTTPResponse.hpp"
#include "net/URI.hpp"
#include <string>

NET_NAMESPACE_BEGIN

class CHTTPCredentials
{
public:
	CHTTPCredentials();
	CHTTPCredentials(const std::string& username, const std::string& password);
	~CHTTPCredentials();

	void fromUserInfo(const std::string& userInfo);
	void fromURI(const CURI& uri);

	void setUsername(const std::string& username);
	const std::string& getUsername() const;
	void setPassword(const std::string& password);
	const std::string& getPassword() const;
	
	void authenticate(CHTTPRequest& request, const CHTTPResponse& response);
	void updateAuthInfo(CHTTPRequest& request);
	void proxyAuthenticate(CHTTPRequest& request, const CHTTPResponse& response);
	void updateProxyAuthInfo(CHTTPRequest& request);

	static bool isBasicCredentials(const std::string& header);
	static bool isDigestCredentials(const std::string& header);
	static bool hasBasicCredentials(const CHTTPRequest& request);
	static bool hasDigestCredentials(const CHTTPRequest& request);
	static bool hasProxyBasicCredentials(const CHTTPRequest& request);
	static bool hasProxyDigestCredentials(const CHTTPRequest& request);
	static void extractCredentials(const std::string& userInfo, std::string& username, std::string& password);
	static void extractCredentials(const CURI& uri, std::string& username, std::string& password);

private:
	CHTTPCredentials(const CHTTPCredentials&);
	CHTTPCredentials& operator = (const CHTTPCredentials&);

	CHTTPDigestCredentials m_digest;
};


NET_NAMESPACE_END

#endif
